/*
 * @Description: 导航信息表单
 * @Author: Rfan
 * @Date: 2022-04-21 15:50:22
 * @LastEditTime: 2022-05-25 08:47:12
 */

import { forwardRef } from 'react';
import { Form, Input, Radio, TreeSelect } from 'antd';
import { useFuncAndNavContext } from '../../../contexts/FuncAndNavContext';
import JPSwitch from '@/components/JPComponents/JPSwitch';

const fieldNames = { label: 'rightsName', value: 'id' };

const InfoForm = () => {
  const { treeData } = useFuncAndNavContext();

  return (
    <>
      <Form.Item name="navLevel" label="菜单层级">
        <Radio.Group>
          <Radio value={1}>子系统</Radio>
          <Radio value={2}>子级菜单</Radio>
        </Radio.Group>
      </Form.Item>
      <Form.Item
        noStyle
        shouldUpdate={(prevValues, currentValues) => prevValues.navLevel !== currentValues.navLevel}
      >
        {({ getFieldValue }) =>
          getFieldValue('navLevel') === 2 ? (
            <Form.Item name="pid" label="上级菜单">
              <TreeSelect
                dropdownStyle={{ maxHeight: 400, overflow: 'auto' }}
                placeholder="=请选择上级菜单="
                allowClear
                treeDefaultExpandAll
                treeData={treeData}
                fieldNames={fieldNames}
              />
            </Form.Item>
          ) : null
        }
      </Form.Item>
      {/* <Form.Item name="rightsCode" label="功能编码"> */}
      {/*  <Input /> */}
      {/* </Form.Item> */}
      <Form.Item name="rightsName" label="名称" rules={[{ required: true }]}>
        <Input />
      </Form.Item>
      <Form.Item
        noStyle
        shouldUpdate={(prevValues, currentValues) => prevValues.navLevel !== currentValues.navLevel}
      >
        {({ getFieldValue }) =>
          getFieldValue('navLevel') === 2 ? (
            <Form.Item
              name="rightsLink"
              label="功能链接"
              rules={[{ required: true }]}
              normalize={(value) => value.trim()}
            >
              <Input />
            </Form.Item>
          ) : (
            <Form.Item name="rightsLink" label="功能链接" normalize={(value) => value.trim()}>
              <Input />
            </Form.Item>
          )
        }
      </Form.Item>

      <Form.Item name="rightsComponent" label="前端组件">
        <Input />
      </Form.Item>
      <Form.Item name="rightsIcon" label="菜单图标">
        <Input />
      </Form.Item>
      <Form.Item name="sortNo" label="排序">
        <Input />
      </Form.Item>
      <Form.Item name="remark" label="备注">
        <Input.TextArea />
      </Form.Item>
      <Form.Item name="cacheRoute" label="是否缓存" valuePropName="checked">
        <JPSwitch activeValue={1} inactiveValue={2} />
      </Form.Item>
      <Form.Item name="openMode" label="外部链接" valuePropName="checked">
        <JPSwitch activeValue={2} inactiveValue={1} />
      </Form.Item>
    </>
  );
};

export default forwardRef(InfoForm);
